<?php 
//error_reporting(0);
$isadmin=1;
include "../comm/tuaninc.php";
include('check.php');

$sql="select id,name,code,type from ".$duoduo->BIAOTOU."service order by id asc";
$s_arr=$duoduo->sqltoarr($sql);

if($_POST['Submit']){
    $arr=$_POST['info'];
	foreach($arr as $k=>$v){
		$field_arr=$v;
		$duoduo->replace_into_sql('service', $field_arr, $alert = 0);
	}
	admin_log('保存在线客服');
	$duoduo->alert('保存完成');
}
if($_GET['act']=='del' && $_GET['id']>0){
    $sql="delete from ".$duoduo->BIAOTOU."service where id='".$_GET['id']."'";
	$duoduo->query($sql);
	admin_log('删除在线客服');
	$duoduo->alert('删除完成');
}
if($_GET['act']=='set'){
    $sql="update ".$duoduo->BIAOTOU."websetting set serviceopen='".$_GET['serviceopen']."'";
	$duoduo->query($sql);
	$duoduo->alert('设置完成');
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>管理中心</title>
<link href="css/style.css" rel="stylesheet" type="text/css">
<script src="js/jquery.js"></script> 
<style type="text/css">
<!--
table,tr,td { font-size:12px;}
table a { text-decoration:none; color:#FF6600}
table a:visted { color:#FF66CC; text-decoration:none}
.STYLE1 {color: #FF6600}
form td{ text-align:center}
-->
</style>
</head>
<body topmargin="5" leftmargin="0">
<table width="98%" border="0" align="center" cellpadding="0" cellspacing="0" >
  <tr>
    <td height="282" valign="top"><table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td>
          <table cellspacing="0" width="100%" height="207" style="border:1px  solid #DCEAF7;">
            <tr>
              <td height="30" colspan="2" bgcolor="E9F2FB" class="bigtext"><strong>&nbsp;<img src="../images/arrow.gif" width="16" height="22" align="absmiddle" /> 客服设置</strong> 状态：<form style="display:inline" action=""><input type="hidden" name="act" value="set" /><label><input name="serviceopen" <?php if(SERVICEOPEN==0){?> checked="checked"<?php }?> type="radio" value="0" />关闭</label><label><input name="serviceopen" <?php if(SERVICEOPEN==1){?> checked="checked"<?php }?> type="radio" value="1" />开启</label><input type="submit" value="提交" /></form></td>
            </tr>
            <tr>
              <td width="100%" colspan="2" valign="top"><table width="100%" height="300" border="0" cellpadding="0" cellspacing="0">
                <tr>
                  <td valign="top" style="padding-top:5px"><form id="form1" name="form1" method="post" action="">
                    <table width="98%"  align="center" border=1 cellpadding=0 cellspacing=0 style="border-collapse: collapse" bordercolor="#dddddd">
                    <tr><td>名称</td><td>类型</td><td>QQ号或者旺旺名</td><td>操作</td></tr>
					  <?php foreach($s_arr as $k=>$v){?>
                      <tr>
                        <td width="" height="30" align="right" class="bigtext">
                        <input type="hidden" name="info[<?=$v['id']?>][id]" value="<?=$v['id']?>" />
						<?=$v['id']?>：<input type="text" name="info[<?=$v['id']?>][name]" style="width:80px; text-align:center" value="<?=$v['name']?>" /> 
                        </td>
                        <td width="" height="30" align="right" class="bigtext">
                        <label><input type="radio" name="info[<?=$v['id']?>][type]" <?php if($v['type']==1){?> checked="checked"<?php }?> value="1" />QQ客服</label>&nbsp;<label><input type="radio" name="info[<?=$v['id']?>][type]" <?php if($v['type']==2){?> checked="checked"<?php }?> value="2" />旺旺客服</label>
                        </td>
                        <td width="" height="30" align="right" class="bigtext">
                        <input type="text" name="info[<?=$v['id']?>][code]" style="width:150px; text-align:center" value="<?=$v['code']?>" /></td>
                        <td width="" height="30" class="bigtext" align="center">&nbsp;
                          &nbsp;<a style="color:#F60" onclick='return confirm("确定要删除?")' href="service_set.php?id=<?=$v['id']?>&act=del">删除</a>
                          </td>
                      </tr>
                      <?php }?>
                      <tr id="sub">
                        <td height="30" class="bigtext" colspan="4">&nbsp;
                          <input type="submit" name="Submit" value="保存设置" />&nbsp;&nbsp;<span id="add" style="cursor:pointer">添加客服</span>
                          </td>
                      </tr>
                    </table>
                    <br />
                  </form>
                  </td>
                </tr>
                <tr>
                   <td align="center"><img src="images/kf_img1.jpg" /></td>
                </tr>
              </table></td>
            </tr>
          </table></td>
        </tr>     
    </table></td>
  </tr>
</table>
<script>
$(function(){
    $('#form1').submit(function(){
		var subm=1;
	    $('#form1 input').each(function(){
		    if($(this).val()==''){
			    $(this).focus();
				alert('该字段不能为空');
				subm=0;
				return false;
			}
		});
		if(subm==0) return false;
		if(subm==1) return true;
	});
	var id=<?=$v['id']?$v['id']:0?>;
	$('#add').click(function(){
		id=id+1;
		var html='<tr><td width="" height="30" align="right" class="bigtext">'+id+'：<input type="text" name="info['+id+'][name]" style="width:80px; text-align:center" value="在线客服" /> </td><td width="" height="30" align="right" class="bigtext"><label><input type="radio" name="info['+id+'][type]"  checked="checked" value="1" />QQ客服</label>&nbsp;<label><input type="radio" name="info['+id+'][type]"  value="2" />旺旺客服</label></td><td width="" height="30" align="right" class="bigtext"><input type="text" name="info['+id+'][code]" style="width:150px; text-align:center" value="" /></td><td></td></tr>'
		$(html).insertBefore("#sub");
	});
})

</script>
</div>
</body>
</html>
